/*
 * ArrayList.op.cpp
 *
 *  Created on: Apr 27, 2011
 *      Author: nathanielclinger
 */

#ifndef ARRAYLIST_OP_CPP_
#define ARRAYLIST_OP_CPP_

#ifndef ARRAYLIST_HPP_
#include "ArrayList.hpp"
#endif

#include <iostream>
using namespace std ;

template <class T>
ArrayList<T> &ArrayList<T>::operator=( const ArrayList<T> &assign )	// assign values from assign to this
{
	if( this != &assign )
	{
		empty() ;	// delete the info from this array list

		al = new T[assign.top] ;	// set al to size of assign
		top = assign.top ;				// set top
		current = assign.current ;		// set current

		for( int i = 0 ; i < assign.current ; i++ )	// copy all the elements from assign to this
			al[i] = assign.al[i] ;
	}

	return *this ;
}

template <class T>
const ArrayList<T> ArrayList<T>::operator+( const ArrayList<T> &other )	// add values from this and other and return a new list of both
{
	ArrayList<T> temp ;		// create a new arraylist

	for( int i = 0 ; i < current ; i++ )
		temp.add( al[i] ) ;	// copy over this values
	for( int i = 0 ; i < other.current ; i++ )	// copy into temp other's values
		temp.add( other.al[i] ) ;

	return temp ;
}

template <class T>
bool ArrayList<T>::operator==( const ArrayList<T> &other )	// check if this and other are same
{
	if( current != other.current )		// if size isn't the same then return false
		return 0 ;

	for( int i = 0 ; i < current ; i++ )		// check that every element in other can be found in this, else return false
		if( !find( other.al[i] ) )
			return 0 ;

	return 1 ;	// if we've reached this point then we are doing good, and we can return true
}

template <class T>
bool ArrayList<T>::operator!=( const ArrayList<T> &other )	// check if this and other are different
{
	return !( *this == other ) ;	// if its not == then its !=
}

template <class T>
ostream &operator<<( ostream &os, const ArrayList<T> &other )	// copy values from other to the ostream
{
	for( int i = 0 ; i < other.current ; i++ )	// for every value in other copy it to os with endl in between
		os << other.al[i].getstring() << endl ;

	return os ;
}

#endif
